//
//  EFADevInfoTCell.m
//  efairy
//
//  Created by XiangDongMBP on 2017/7/14.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFADevInfoTCell.h"
#import "EFAModel.h"

@interface EFADevInfoTCell ()
@property (nonatomic, strong) NSArray<NSString *> *titleArray;
@end

@implementation EFADevInfoTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.leftLabel.text = @"";
    self.rightLabel.text = @"";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)configViewWithEFADeviceInfoModel:(EFADeviceInfoModel *)model indexPath:(NSIndexPath *)indexPath {
    if (!model) {
        return;
    }
    if(indexPath.row == 0){
        self.leftLabel.font = [UIFont boldSystemFontOfSize:16.f];
        
    }
        
    EFADeviceListItem *info = model.device_info;
    EFADevRealTimeData *realTime = model.realtime_data;
    NSString *heartRateStr = [NSString stringWithFormat:@"%ldS", (long)realTime.heartRate];
    NSString *muteModeStr = realTime.muteMode ? @"正常" : @"静音";
    NSArray *value = @[info.efairydevice_project_name ? info.efairydevice_project_name : @"",
                       [NSString stringWithFormat:@"%ld", (long)info.efairydevice_id],
                       info.ccid ? info.ccid : @"",
                       info.uuid_address ? info.uuid_address : @"",
                       info.efairydevice_install_time ? info.efairydevice_install_time : @"",
                       info.efairydevice_address ? info.efairydevice_address : @"",
                       info.efairydevice_is_online ? @"在线" : @"离线",
                       info.three_state_attStr,
                       realTime.tsStr ? realTime.tsStr : @"",
                       heartRateStr,
                       muteModeStr];
    if (indexPath.row < self.titleArray.count) {
        if(indexPath.row == 0){
            self.leftLabel.text =  info.efairydevice_name ? info.efairydevice_name : @"";
            self.rightLabel.text = [NSString stringWithFormat:@"%@%02ld", (info.efairydevice_version_date ? info.efairydevice_version_date : @""), (long)info.efairydevice_version];
        }else{
             self.leftLabel.text = self.titleArray[indexPath.row];
            NSObject *obj = value[indexPath.row];
            if ([obj isKindOfClass:[NSString class]]) {
                self.rightLabel.text = (NSString *)obj;
            } else {
                self.rightLabel.attributedText = (NSAttributedString *)obj;
            }
        }
       
        return;
    }
    
    EFADevRealTimeDataItem *item = model.realtime_data.filterData[indexPath.row - self.titleArray.count];
    self.leftLabel.text = [NSString stringWithFormat:@"%@通道%ld", item.cidTitle, (long)item.cidDisplay];
    self.rightLabel.text = item.rtvValue;
}

#pragma mark - getters and setters
- (NSArray<NSString *> *)titleArray {
    if (!_titleArray) {
        _titleArray = @[//@"设备名称",
                        @"所属项目",
                        @"设备ID",
                        @"设备主编码",
                        @"设备从编码",
//                        @"设备软件版本",
                        @"安装日期",
                        @"安装位置",
                        @"无线通讯状态",
                        @"报警状态",
                        @"数据更新时间",
                        @"心跳间隔",
                        @"音响模式"];
    }
    return _titleArray;
}

@end
